package com.yadong.smarthome2.messageparser;

import android.text.TextUtils;

import com.yadong.smarthome2.device.Device;
import com.yadong.smarthome2.device.Device.DeviceConnectionType;
import com.yadong.smarthome2.protocol2.ALog;

public class DeviceInfoParser implements MessageParser<Device>{

    @Override
    public Device parseMessage(String message) {
        if (TextUtils.isEmpty(message)) {
            ALog.loge(this, "error to parse message, message is null");
            return null;
        }
        String splits[] = message.split(",");
        if (splits.length != 3) {
            ALog.loge(this, "error to parse message, message format error");
            return null;
        }
        String addressAndrPort = splits[0];
        String description = splits[1];
        String mac = splits[2];
        Device device = new Device(DeviceConnectionType.WIFI,
                addressAndrPort, description, mac);
        return device;
    }

}
